/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wumpusworld;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import wumpusworld.ControlWindow;

/**
 *
 * @author Macias
 */
public class MyKeyListener implements KeyListener{

    public final static int CONTROL_WINDOW = 1;
    public final static int OPTIONS_WINDOW = 2;
    public final static int SHOOT_WINDOW =   3;


ControlWindow controlWindow;
MainWindow mainWindow;
MapOptionsWindow optionsWindow;
ShootDirectionWindow shootWindow;
/**
 * parameter which indicates which window is using Key Listener : 1-ControlWindow/MainWindow ; 2- MapOptionsWindow
 * 3 - ShootWindow
 * acording to this param different keys are calling different methods
 */
int param;

/**
 * key listener for windows
 * @param window class which is the parent for key listener
 * @param param indicates which window is parent 1-ControlWindow/MainWindow ;2-MapOptionsWindow
 */
MyKeyListener(Object window,int param){
    this.param = param;
    switch(param){
        case CONTROL_WINDOW: this.controlWindow = (ControlWindow) window;
            break;
        case OPTIONS_WINDOW: this.optionsWindow = (MapOptionsWindow) window;
            break;
        case SHOOT_WINDOW: this.shootWindow = (ShootDirectionWindow) window;
            break;
        default: break;
    }

//    if(param==1)
//        this.controlWindow = (ControlWindow) window;
//    else
//        this.optionsWindow = (MapOptionsWindow) window;
           
}

    public void keyTyped(KeyEvent e) {
//        switch(e.getKeyCode()){
//
//            case KeyEvent.VK_LEFT:
//                    controlWindow.performMoveWest();
//                    break;
//            case KeyEvent.VK_RIGHT:
//                    controlWindow.performMoveSouth();
//                        break;
//            case KeyEvent.VK_DOWN:
//                    controlWindow.performMoveSouth();
//                        break;
//            case KeyEvent.VK_UP:
//                    controlWindow.performMoveSouth();
//                        break;
//            default: break;
//        }
    }

    public void keyPressed(KeyEvent e) {
        switch(param){
            case CONTROL_WINDOW:                          //key list for ControlWindow/MainWindow
                switch(e.getKeyCode()){
                        case KeyEvent.VK_LEFT:
                                controlWindow.performMoveWest();
                                break;
                        case KeyEvent.VK_RIGHT:
                                controlWindow.performMoveEast();
                                    break;
                        case KeyEvent.VK_DOWN:
                                controlWindow.performMoveSouth();
                                    break;
                        case KeyEvent.VK_UP:
                                controlWindow.performMoveNorth();
                                    break;
                        case KeyEvent.VK_S:
                                controlWindow.performShoot();
                                break;
                        case KeyEvent.VK_F2:
                                controlWindow.performNewGame();
                                break;

                        default: break;
                    }
                  break;
            case OPTIONS_WINDOW:                     //key list for ControlWindow/MainWindow
                     switch(e.getKeyCode()){
                        case KeyEvent.VK_LEFT:
                                optionsWindow.decreaseAmountOfObstacles();
                                break;
                        case KeyEvent.VK_RIGHT:
                                optionsWindow.increaseAmountOfObstacles();
                                    break;
                        case KeyEvent.VK_DOWN:
                                optionsWindow.decreaseMapSize();
                                    break;
                        case KeyEvent.VK_UP:
                                optionsWindow.increaseMapSize();
                                    break;

                        case KeyEvent.VK_ENTER:
                                optionsWindow.performOkClick();
                                break;
                        case KeyEvent.VK_ESCAPE:
                                optionsWindow.performCancelClick();
                                break;
                        default: break;
                    }
                 break;
            case SHOOT_WINDOW:
                    switch(e.getKeyCode()){
                        case KeyEvent.VK_LEFT:
                                shootWindow.performWestClick();
                                break;
                        case KeyEvent.VK_RIGHT:
                                shootWindow.performEastClick();
                                    break;
                        case KeyEvent.VK_DOWN:
                                shootWindow.performSouthClick();
                                    break;
                        case KeyEvent.VK_UP:
                                shootWindow.performNorthClick();
                                    break;
                        case KeyEvent.VK_ESCAPE:
                                shootWindow.dispose();
                                break;
                        default: break;
                    }
                    break;
            default: break;
        }
//        if(param==1)                //key list for ControlWindow/MainWindow
//            switch(e.getKeyCode()){
//                case KeyEvent.VK_LEFT:
//                        controlWindow.performMoveWest();
//                        break;
//                case KeyEvent.VK_RIGHT:
//                        controlWindow.performMoveEast();
//                            break;
//                case KeyEvent.VK_DOWN:
//                        controlWindow.performMoveSouth();
//                            break;
//                case KeyEvent.VK_UP:
//                        controlWindow.performMoveNorth();
//                            break;
//
//                case KeyEvent.VK_F2:
//                        controlWindow.performNewGame();
//                        break;
//
//                default: break;
//            }
//        if(param==2)            //key list for ControlWindow/MainWindow
//            switch(e.getKeyCode()){
//                case KeyEvent.VK_LEFT:
//                        optionsWindow.decreaseAmountOfObstacles();
//                        break;
//                case KeyEvent.VK_RIGHT:
//                        optionsWindow.increaseAmountOfObstacles();
//                            break;
//                case KeyEvent.VK_DOWN:
//                        optionsWindow.decreaseMapSize();
//                            break;
//                case KeyEvent.VK_UP:
//                        optionsWindow.increaseMapSize();
//                            break;
//
//                case KeyEvent.VK_ENTER:
//                        optionsWindow.performOkClick();
//                        break;
//                case KeyEvent.VK_ESCAPE:
//                        optionsWindow.performCancelClick();
//                        break;
//                default: break;
//            }

    }

    public void keyReleased(KeyEvent e) {
        
    }



    public void setControlWindow(ControlWindow controlWind){
        this.controlWindow = controlWind;
    }

    public void setMainWindow(MainWindow mainWind){
        this.mainWindow = mainWind;
    }
    
}
